#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <string.h>


#define NUM 128
#define CMD_NUM 64

int main()
{
  char command[NUM];
  for(;;)
  {
    char* argv[CMD_NUM]={NULL};

    command[0]=0;
    printf("[zyl@myhostname mydir]# ");
    fflush(stdout);

    fgets(command,NUM,stdin);
    command[strlen(command)-1]='\0';

    const char* sep=" ";
    argv[0]=strtok(command,sep);
    int i=1;
    while(argv[i]=strtok(NULL,sep))
    {
      i++;
    }


    if(strcmp(argv[0],"cd")==0)
    {
      if(argv[1]!=NULL)
      {
        chdir(argv[1]);
        continue;
      }
    }


    if(fork()==0)
    {
      execv(argv[0],argv);
      exit(1);
    }

    waitpid(-1,NULL,0);
  }
  return 0;
}
